#ifndef BUFFER_H
#define BUFFER_H

#include "stdio.h"
#include "stdint.h"

struct FEBuffer {
    FEBuffer *parent;
    uint64_t parent_bit_offset;
    uint64_t parent_bit_len;

    char *name;

    FILE *file; //文件指针，文件buffer有效
    char *ptr;  //内存buffer: 数据指针 文件buffer: cache指针
    uint64_t data_len; //buffer数据长度
    uint64_t ptr_offset; //ptr相对数据头偏移
    uint64_t ptr_len; //ptr内存空间长度
    uint64_t cache_len; //cache数据长度
    //锁
};

FEBuffer *newFileFEBuffer(const char *name, const char *file);
FEBuffer *newMemoryFEBuffer(const char *name, FEBuffer *parent, uint64_t parent_offset, uint64_t parent_len, char *ptr, uint64_t len);
void deleteFEBuffer(FEBuffer *buffer);
char *fetchFEBuffer(FEBuffer *buffer, uint64_t offset, uint64_t len);

#endif // BUFFER_H
